package com.cheng.controller;

import com.cheng.common.exception.CommonException;
import com.cheng.common.results.DataRslt;
import com.cheng.common.utils.DateUtil;
import com.cheng.data.vo.AcceptInfoVO;
import com.cheng.operation.AcceptInfoOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * @author: ChengJW
 * @date: 2021/12/1 21:33
 * @version: 1.0
 * @description: 档案数字化业务处理类
 */
@Controller
public class ArchivesDigitizingController extends BaseController{

    private final static Logger log = LoggerFactory.getLogger(ArchivesDigitizingController.class);

    @Autowired
    private AcceptInfoOperation acceptInfoOperation;

    @RequestMapping("/circulation/archivesDigitizing")
    public String archivesDigitizing(){
        return "archivesDigitizing";
    }

    @RequestMapping("/circulation/archivesDigitized")
    public String archivesDigitized(){
        return "archivesDigitized";
    }

    @RequestMapping("/circulation/archivesAccept")
    public String archivesAcceptInfo(){
        return "archivesAcceptInfo";
    }

    /**
    * @author: ChengJW
    * @params: []
    * @return: com.cheng.common.results.DataRslt
    * @date: 2021/12/2
    * @description: 修改受理状态 01 档案数字化；02 数字化完成；03 档案入库
    */
    @RequestMapping("/circulation/archivesDigitizing/updateAceptInf")
    @ResponseBody
    public DataRslt updateArchivesDigitizing(@RequestParam("atBussIdList") List<String> atBussIdList, String pdTpCd) throws CommonException {
        if (null != atBussIdList && atBussIdList.size() > 0){
            for (String atBussId : atBussIdList){
                AcceptInfoVO vo = new AcceptInfoVO();
                vo.setAtBussId(atBussId);
                vo.setUtDt(DateUtil.dateToStr(new Date(),"yyyy-MM-dd hh:MM:ss"));
                if ("01".equals(pdTpCd)) {
                    vo.setAtAcptStd("030001");
                    vo.setAtAcptDt2(new Date());
                }else if ("02".equals(pdTpCd)){
                    vo.setAtAcptStd("030002");
                    vo.setAtAcptDt3(new Date());
                }else if ("03".equals(pdTpCd)){
                    vo.setAtAcptStd("030003");
                    vo.setAtAcptDt4(new Date());
                }
                acceptInfoOperation.updateAcceptInfo(vo);
            }
            return success();
        }
        return failure();
    }
}
